package com.axsoft.jobimp.tests;

import junit.framework.TestCase;

import com.axsoft.jobimp.OHeader;
import com.axsoft.jobimp.types.BLK;
import com.axsoft.jobimp.types.LongWord;
import com.axsoft.jobimp.types.Word;

public class OHeaderTest extends TestCase {
	
	public void testOHeaderZero() {
		final OHeader header = new OHeader();
		final BLK blk = header.toBLK();
		final byte[] bytes = blk.getData();
		
		final byte[] bytesExpected = {  0x23, 							// Constant command
										0x00, 0x00, 0x00, 0x00,			// Sequence
										0x00, 0x00,						// Type
										0x00, 0x00,						// SubType
										0x00, 0x00, 0x00, 0x00,			// Request Id
										0x00, 0x00, 0x00, 0x00  };		// Data Length
		
		assertEquals(bytesExpected.length, bytes.length);
		assertTrue(OTestUtils.byteArraysEquals(bytes, bytesExpected));
	}
	
	public void testOHeaderRaw() {
		final OHeader header = new OHeader(Integer.MAX_VALUE, Short.MAX_VALUE, Short.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE);
		final BLK blk = header.toBLK();
		final byte[] bytes = blk.getData();
		
		final byte[] bytesExpected = {  0x23, 												// Constant command
										0x7F, (byte)0xFF, (byte)0xFF, (byte)0xFF,			// Sequence
										0x7F, (byte)0xFF,									// Type
										0x7F, (byte)0xFF,									// SubType
										0x7F, (byte)0xFF, (byte)0xFF, (byte)0xFF,			// Request Id
										0x7F, (byte)0xFF, (byte)0xFF, (byte)0xFF  };		// Data Length
		
		assertEquals(bytesExpected.length, bytes.length);
		
		for (int i = 0; i < bytesExpected.length; i++) {
			assertEquals(bytesExpected[i], bytes[i]);
		}
	}
	
	public void testOHeaderObj() {
		final OHeader header = new OHeader(new LongWord(Integer.MAX_VALUE), new Word(Short.MAX_VALUE), new Word(Short.MAX_VALUE), new LongWord(Integer.MAX_VALUE), new LongWord(Integer.MAX_VALUE));
		final BLK blk = header.toBLK();
		final byte[] bytes = blk.getData();
		
		final byte[] bytesExpected = {  0x23, 												// Constant command
										0x7F, (byte)0xFF, (byte)0xFF, (byte)0xFF,			// Sequence
										0x7F, (byte)0xFF,									// Type
										0x7F, (byte)0xFF,									// SubType
										0x7F, (byte)0xFF, (byte)0xFF, (byte)0xFF,			// Request Id
										0x7F, (byte)0xFF, (byte)0xFF, (byte)0xFF  };		// Data Length
		
		assertEquals(bytesExpected.length, bytes.length);
		
		for (int i = 0; i < bytesExpected.length; i++) {
			assertEquals(bytesExpected[i], bytes[i]);
		}
	}

}
